﻿package commands 
{
	import flash.utils.ByteArray;
	import commands.classesinfo.*;
	
	/**
	 * ...
	 * @author wwx
	 * 50000008 游戏结果
	 */
	public class ResultOfGameCmd extends abCommand 
	{
		
		public function ResultOfGameCmd() //: abCommand(CommandType.CMD_TYPE_RESULTOFGAME) 
		{
			super(CommandType(CommandType.CMD_TYPE_RESULTOFGAME));
			poolsInfo = new Array();
		}
		
		public var msgSeq:int;//消息号
		public var errorNum:int;//错误号

		public var deskId:int;
		public var countOfPool:int;
		public var poolsInfo:Array;//PoolInfo;
		
		public function convertToCmd(bytes:ByteArray, offset:int, len:int):int
		{
			var ret:int = -1;
			msgSeq = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
			offset += 4;
			errorNum = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			deskId = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			countOfPool = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			//poolsInfo = new Array();
			var poolInfo:PoolInfo = null;
			var winnerInfo:WinnerInfo = null;
			for (var i:int = 0; i < countOfPool; i++)
			{
				poolInfo = new PoolInfo();
				poolInfo.poolId = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
				offset += 4;
				poolInfo.countOfWinners = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
				offset += 4;
				
				//poolInfo.winnersInfo = new Array();
				for (var j:int = 0; j < poolInfo.countOfWinners; j++)
				{
					winnerInfo = new WinnerInfo();
					winnerInfo.winnerId = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;
					winnerInfo.type = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;
					winnerInfo.chipOfWin = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
					offset += 4;

					poolInfo.winnersInfo[i] = winnerInfo;					
				}
				poolsInfo[i] = poolInfo;
			}
			return 0;
		}		
	}
	
}